
import type { MaProTableColumns, MaProTableExpose } from '@mineadmin/pro-table'
// import type { UsemaDrawerExpose } from '@/hooks/usemaDrawer.ts'

import { ElTag } from 'element-plus'
import { useMessage } from '@/hooks/useMessage.ts'
import { deleteByIds, resetPassword } from '~/base/api/user.ts'
import { ResultCode } from '@/utils/ResultCode.ts'

export default function getTableColumns(maDrawer: any, formRef: any): MaProTableColumns[] {
  const msg = useMessage()
  return [
    // 展开列
    {width: '80px', type: 'expand',
      cellRender: ({ row }) => (
        <div class="flex-center">
          {row.id}
        </div>
      )
    },
    // 多选列
    { type: 'selection', showOverflowTooltip: false},
    // 索引序号列
    // { type: 'index' },
    // 普通列
    { label: '用户编号', prop: 'phone' },
    { label: '头像', prop: 'xxx', width: '80px',
      cellRender: ({ row }) => (
        <el-image preview-teleported={true} src={row.avatar} preview-src-list={[row.avatar]} />
      ),
    },
    { label: '用户名', prop: 'phone' },
    { label: '用户名称', prop: 'phone' },
    { label: '用户等级', prop: 'xxx' },
    { label: '余额', prop: 'xxx' },
    { label: '消费', prop: 'xxx' },
    { label: '佣金', prop: 'xxx' },
    { label: '下级数', prop: 'xxx' },
    { label: '上级ID', prop: 'xxx' },
    { label:'状态', prop: 'xxx',
      cellRender: ({ row }) => (
        <switch v-model={row.state} active-value={1} inactive-value={0} active-text="启用" inactive-text="禁用" />
      ),
    },

    // 操作列
    {
      type: 'operation',
      label:'操作',
      fixed: 'right',
      width: '180px',
      operationConfigure: {
        type: 'tile',
        actions: [
          {
            name: 'edit',
            icon: 'material-symbols:person-edit',
            text: '编辑',
            onClick: ({ row }) => {
              maDrawer.setTitle('编辑')
              maDrawer.open({ formType: 'edit', data: row })
            },
          },
          {
            name: 'dist',
            icon: 'material-symbols:person-edit',
            text: '详情',
            onClick: ({ row }) => {
              maDrawer.setTitle('详情')
              maDrawer.open({ formType: 'edit', data: row })
            },
          },
          {
            name: 'del',
            icon: 'mdi:delete',
            text: '删除',
            onClick: ({ row }, proxy: MaProTableExpose) => {
              msg.delConfirm('确定删除吗').then(async () => {
                const response = await deleteByIds([row.id])
                if (response.code === ResultCode.SUCCESS) {
                  msg.success('删除成功')
                  proxy.refresh()
                }
              })
            },
          }
        ],
      },
    },
  ]
}
